#include "Config.h"
#include "Common/Atoi.h"
#include "GameConfig.h"
#include "DB/DBExecutor.h"
#include "Server.h"
#include "DBCache/DBDataExecHelper.h"

GameConfig gameConfig;

GameConfig::GameConfig()
{

}

GameConfig::~GameConfig()
{

}

bool GameConfig::loadGameConfig()
{
	std::unique_ptr<DBExecutor> execu(gDataDBConnectionMgr->GetExecutor());
	if (execu.get() == NULL || !execu->isConnected()) return false;
	DBConfigData dcd;
	if (execu->Prepare("SELECT `key`, `value` FROM `config`", dcd) != DB_OK)
		return false;
	while (execu->Next() == DB_OK)
	{
		if (dcd._key.compare("card_turn") == 0)
			_cardTurn = Atoi<UInt32>(dcd._value);
		else if (dcd._key.compare("dismiss_room") == 0)
			_dismissRoom = Atoi<UInt32>(dcd._value);
		else if (dcd._key.compare("init_card") == 0)
			_initCard = Atoi<UInt32>(dcd._value);
		else if (dcd._key.compare("init_coin") == 0)
			_initCoin = Atoi<UInt32>(dcd._value);
		else if (dcd._key.compare("promoter_coin") == 0)
			_promoterCoin = Atoi<UInt32>(dcd._value);
		else if (dcd._key.compare("promoter_card") == 0)
			_promoterCard = Atoi<UInt32>(dcd._value);
	}
	return true;
}
